package com.droidclaimcustomer.dal;

import java.util.List;

import android.content.Context;

import com.droidclaimcustomer.helper.asyntask.IProgressTracker;
import com.droidclaimcustomer.helper.asyntask.ProgressAsynTask;
import com.droidclaimcustomer.helper.asyntask.SpinnerTracker;

public class DatabaseLoader<T, P> extends ProgressAsynTask<P, List<T>> {
	DAL<T, P> dal;

	public DatabaseLoader(Context context, String progressLabel) {
		if (progressLabel != null) {
			IProgressTracker tracker = new SpinnerTracker(context,progressLabel);
			setProgressTracker(tracker);
		}
	}

	public void setDAL(DAL<T, P> dal) {
		this.dal = dal;
	}

	@Override
	protected List<T> performTaskInBackground(P... parameters) throws Exception {
		List<T> result = null;

		dal.open();
		// Cursor cursor = dal.getAllCursor();
		// result = dal.mapCursor(getTaskId(), cursor, parameters);
		result = dal.getAll(getTaskId(), parameters);
		dal.close();

		return result;
	}

}
